import { Time } from '@/utils/serverTime'
// 开始时间
export function setStarTime(time: string) {
  if (!time) return 0
  let T = new Time(`${time}T00:00:00Z`).toTimestamp() - new Time().getTimeZoneOffsetM()
  return T
}

// 结束时间
export function setEndTime(time: string) {
  if (!time) return 0
  let T = new Time(`${time}T23:59:59Z`).toTimestamp() - new Time().getTimeZoneOffsetM()
  return T
}

// 设置时间查询开始结束
export function setTimeValue(query: any) {
  if (query.date && query.date[0] && query.date[1]) {
    query.start_time = setStarTime(query.date[0])
    query.end_time = setEndTime(query.date[1])
  } else {
    query.start_time = 0
    query.end_time = 0
  }
  return query
}
// 设置单时间查询
export function setTimeDateValue(query: any) {
  if (query.date) {
    query.start_time = setStarTime(query.date)
    query.end_time = setEndTime(query.date)
  } else {
    query.start_time = 0
    query.end_time = 0
  }
  return query
}

// 时间戳转选择器时间(年月日 时分秒)
export function setTimestampTime(number: number) {
  if (!number) return '-'
  return new Time(number*1000).format()
  // return new Time(number*1000).timeFormat()
}

// 时间戳转选择器时间(年月日)
export function setTimestampTimeDate(number: number) {
  if (!number) return '-'
  return new Time(number*1000).format().substring(0, 10)
  // return new Time(number*1000).timeFormat().substring(0, 10)
}

// 0代表今日,-1代表昨日
export function getDateDay(dates: number) {
  let day = '';
  switch (dates) {
    case -1:
      day = new Time().getSpecialTime().getYesterday()[0].format().substring(0, 10)
    break;
    case 0:
      day = new Time().format().substring(0, 10)
    break;
  }
  return day
}

// dates为数字类型，不传或0代表本周，-1代表上周
export function getWeek(dates: number) {
  let week: any[] = [];
  switch (dates) {
    case -1:
      week = [new Time().getSpecialTime().getLastWeek()[0].format().substring(0, 10),new Time().getSpecialTime().getLastWeek()[1].format().substring(0, 10)]
    break;
    case 0:
      week = [new Time().getSpecialTime().getThisWeek()[0].format().substring(0, 10),new Time().getSpecialTime().getThisWeek()[1].format().substring(0, 10)]
    break;
  }
  return week
}
export function getSevenWeek() {
  let week: any[] = [];
  week = [new Time().getSpecialTime().getLatestWeek()[0].format().substring(0, 10),new Time().getSpecialTime().getLatestWeek()[1].format().substring(0, 10)]
  return week
}

// dates为数字类型，不传或0代表本月，-1代表上月
export function getMonth(dates: number) {
  let month: any[] = [];
  switch (dates) {
    case -1:
      month = [new Time().getSpecialTime().getLastMonth()[0].format().substring(0, 10),new Time().getSpecialTime().getLastMonth()[1].format().substring(0, 10)]
    break;
    case 0:
      month = [new Time().getSpecialTime().getThisMonth()[0].format().substring(0, 10),new Time().getSpecialTime().getThisMonth()[1].format().substring(0, 10)]
    break;
  }
  return month
}

// 获取时间是否为一天之内  
export const isOneDay = (date:string[]):boolean => {
  if (setEndTime(date[1]) - setStarTime(date[0]) == 86399 ) {
    return true 
  } else {
    return false
  }
}